<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="客户姓名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员等级" prop="memberGrade">
        <el-input
          v-model="queryParams.memberGrade"
          placeholder="请输入会员等级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油品" prop="oilName">
        <el-select
          v-model="queryParams.oilName"
          placeholder="请选择油品"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in oilNameOptions"
            :key="dict.dictLabel"
            :label="dict.dictLabel"
            :value="dict.dictLabel"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          type="info"
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="manageList">
      <af-table-column label="会员id" align="left" prop="memberId" />
      <af-table-column label="" align="left" prop="unionId" v-if="false" />
      <af-table-column label="" align="left" prop="minaUserId" v-if="false" />
      <af-table-column label="客户姓名" align="left" prop="customerName" />
      <af-table-column label="会员等级" align="left" prop="grade" />
      <af-table-column label="手机号" align="left" prop="phoneNumber" />
      <af-table-column label="油品" align="left" prop="oilName" />
      <af-table-column label="汽油余额" align="left" prop="qyAmt" />
      <af-table-column label="柴油余额" align="left" prop="cyAmt" />
      <af-table-column label="积分" align="left" prop="integral" />
      <af-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="lookinfo(scope.row)"
            >订单查询</el-button
          >
        </template>
      </af-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :title="titleOrderInfo"
      :visible.sync="openOrderInfo"
      width="700px"
      append-to-body
    >
      <el-table :data="orderList">
        <af-table-column
          v-if="false"
          label="订单id"
          align="left"
          prop="orderId"
        />
        <af-table-column
          label="订单号"
          width="200"
          align="left"
          prop="orderNo"
        />
        <af-table-column label="油品名称" align="left" prop="oilName" />
        <af-table-column label="油品价格" align="left" prop="oilPirce" />
        <af-table-column label="加油升数" align="left" prop="orderLiters" />
        <af-table-column label="金额" align="left" prop="amt" />
        <af-table-column
          label="消费者"
          width="120"
          align="left"
          prop="consumer"
        />
        <af-table-column
          label="加油员"
          width="120"
          align="left"
          prop="oilPersonnel"
        />
        <af-table-column label="加油枪号" align="left" prop="oilGun" />
        <af-table-column
          label="支付类型"
          align="left"
          prop="payType"
          :formatter="payTypeFotmat"
        />
        <af-table-column
          label="油站名称"
          width="120"
          align="left"
          prop="stationName"
          v-if="false"
        />
        <af-table-column
          label="用户id(消费者)"
          align="left"
          prop="consumerId"
          v-if="false"
        />
        <af-table-column
          label="油站id"
          align="left"
          prop="stationId"
          v-if="false"
        />
        <af-table-column
          label="状态"
          align="left"
          prop="status"
          :formatter="statusFotmat"
        />
        <af-table-column
          label="支付时间"
          align="left"
          prop="payDate"
          width="150"
        >
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.payDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
        <af-table-column
          label="创建时间"
          align="left"
          prop="createdDate"
          width="150"
        >
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.createdDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
        <af-table-column
          label="订单类型"
          align="left"
          prop="orderType"
          v-if="false"
        />
      </el-table>
      <pagination
        v-show="totalOrder > 0"
        :total="totalOrder"
        :page.sync="queryOrder.pageNum"
        :limit.sync="queryOrder.pageSize"
        @pagination="listPage"
      />
    </el-dialog>
  </div>
</template>

<script>
import { listManage, getOrderInfo } from "@/api/customer/manage";
import { stationinfo } from "@/api/station/gun";
import { listPrice } from "@/api/station/price";
export default {
  name: "Manage",
  data() {
    return {
      // 总条数
      total: 0,
      totalOrder: 0,
      // 客户管理表格数据
      manageList: [],
      //油站信息
      stationOptions: [],
      orderList: [],
      // 是否显示弹出层
      openOrderInfo: false,
      titleOrderInfo: "",
      oilNameOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: null,
        commendMan: null,
        memberGrade: null,
        phoneNumber: null,
        oilName: null,
      },
      queryOrder: {
        pageNum: 1,
        pageSize: 10,
        oilName: null,
        stationId: null,
        consumerId: null,
      },
    };
  },
  created() {
    this.getList();
    stationinfo().then((response) => {
      this.stationOptions = response.rows;
    });
    listPrice().then((response) => {
      this.oilNameOptions = response.rows;
    });
  },
  methods: {
    payTypeFotmat(row, column) {
      if (row.payType === "sxf") {
        return "随行付";
      } else if (row.payType === "dzk") {
        return "电子卡";
      } else if (row.payType === "wx") {
        return "微信";
      } else if (row.payType === "zfb") {
        return "支付宝";
      } else if (row.payType === "xj") {
        return "现金";
      }
    },
    statusFotmat(row, column) {
      if (row.status === "0") {
        return "未支付";
      } else if (row.status === "1") {
        return "已支付";
      }
    },
    /** 查询客户管理列表 */
    getList() {
      listManage(this.queryParams).then((response) => {
        this.manageList = response.rows;
        this.total = response.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    lookinfo(row) {
      row.page = this.queryOrder.pageNum;
      row.limit = this.queryOrder.pageSize;
      this.listPage(row);
    },
    listPage(row) {
      this.queryOrder.consumerId = row.minaUserId;
      this.queryOrder.pageNum = row.page;
      this.queryOrder.pageSize = row.limit;
      getOrderInfo(this.queryOrder).then((response) => {
        this.orderList = response.rows;
        this.openOrderInfo = true;
        this.totalOrder = response.total;
        this.titleOrderInfo = "查看客户订单信息";
      });
    },
  },
};
</script>
